XML GENERATE
The XML GENERATE statement converts data to XML format.
General Format
XML GENERATE Xml-Stream FROM Xml-Data
 
    [ WITH ENCODING  Code-page  ]
 
    [ COUNT IN Counter ]
 
    [ ON EXCEPTION Imperative-Statement-1 ]
 
    [ NOT ON EXCEPTION Imperative-Statement-2 ]
[END-XML]
Syntax Rules
1. Xml-Stream must reference an elementary data item of category alphanumeric, an alphanumeric group item or an elementary data item of category national. If it references an alphanumeric group item, then it is treated as though it were an elementary data item of category alphanumeric.
2. Xml-Data can be a group or elementary data-item. It cannot be a function identifier or be reference modified, but it can be subscripted, and must not overlap with Xml-Stream or Counter.
3. Code-page must be numeric data item or literal.
4. Counter must be a numeric data item.
General Rules
1. If specified, Code-page indicates the encoding used in the XML stream; possible values are:
Code-page
Encoding
37
273
277
278
280
284
285
290
297
300
420
424
437
500
775
813
819
833
834
850
852
855
857
858
860
861
862
863
864
865
866
868
869
870
871
874
875
912
914
915
916
918
920
921
922
930
932
933
935
936
937
939
942
943
948
949
IBM037
IBM273
IBM277
IBM278
IBM280
IBM284
IBM285
IBM290
IBM297
x-IBM300
IBM420
IBM424
IBM437
IBM500
IBM775
ISO-8859-7
ISO-8859-1
x-IBM833
x-IBM834
IBM850
IBM852
IBM855
IBM857
IBM00858
IBM860
IBM861
IBM862
IBM863
IBM864
IBM865
IBM866
IBM868
IBM869
IBM870
IBM871
x-IBM874
x-IBM875
ISO-8859-2
ISO-8859-4
ISO-8859-5
ISO-8859-8
IBM918
ISO-8859-8
x-IBM921
x-IBM922
x-IBM930
x-MS932_0213
x-IBM933
x-IBM935
x-mswin-936
x-IBM937
x-IBM939
x-IBM942
x-IBM943
x-IBM948
x-IBM949
950
964
970
1025
1026
1046
1097
1098
1112
1122
1123
1124
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1166
1200
1208
1250
1251
1252
1253
1254
1255
1256
1257
1258
1364
1381
1383
33722
62210
62222
62238
x-IBM950
x-IBM964
x-IBM970
x-IBM1025
IBM1026
x-IBM1046
x-IBM1097
x-IBM1098
x-IBM1112
x-IBM1122
x-IBM1123
x-IBM1124
IBM01140
IBM01141
IBM01142
IBM01143
IBM01144
IBM01145
IBM01146
IBM01147
IBM01148
IBM01149
x-IBM1166
UTF-16
UTF-8
windows-1250
windows-1251
windows-1252
windows-1253
windows-1254
windows-1255
windows-1256
windows-1257
windows-1258
x-IBM1364
x-IBM1381
x-IBM1383
x-IBM33722
ISO-8859-8
ISO-8859-9
ISO-8859-9
2. the If the COUNT IN phrase is specified, after execution of the XML GENERATE statement Counter contains the count of generated XML character positions.
3. An exception condition exists when an error occurs during generation of the XML document, for example if Xml-Stream is not large enough to contain the generated XML document. In this case the XML generation stops and the content of the receiver is undefined. If the COUNT IN phrase is specified, Counter contains the number of character positions that were generated, which can range from 0 to the length of Xml-Stream. If the ON EXCEPTION phrase is specified, control is transferred to Imperative-Statement-1, otherwise control is transferred to the end of the XML GENERATE statement.
4. If an exception condition does not occur during generation of the XML document, control is passed to Imperative-Statement-2, if specified, otherwise to the end of the XML GENERATE statement.
5. When the statement completes, two special registers are set:
o XML-CODE contains the error type. Possible values are
0
Ok
1
Warning
10
Recoverable Error
100
Fatal Error
o XML-ERRMSG contains the error message string, if an error occurred.
Examples
Generate an XML structure from a data structure
working-storage section.
 01 my-html.
    05 my-head  pic x(10value "first".
    05 my-body.
       10 my-paragraph pic x(20value "paragraph 1".
       10 my-table.
          15 my-row-1.
             20 my-col-1 pic x(20value "col 1"
             20 my-col-2 pic x(20value "col 2"
          15 my-row-2.
             20 my-col-1 pic x(20value "col 1"
             20 my-col-2 pic x(20value "col 2"
 01 the-xml  pic x any length.
 
 procedure division.
 main.
  xml generate the-xml from my-html
  end-xml
  display the-xml.
*> It will display the following:
*> <my-html><my-head>first</my-head><my-body><my-paragraph>paragraph 1</my-paragraph><my-table><my-row-1><my-col-1>col 1</my-col-1><my-col-2>col 2</my-col-2></my-row-1><my-row-2><my-col-1>col 1</my-col-1><my-col-2>col 2</my-col-2></my-row-2></my-table></my-body></my-html>